package com.hg.library.ui;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.hg.highglass_library.R;
import com.hg.library.ui.imageview.BatteryWhite;
import com.hg.library.ui.textview.LanTingHeiText;

/**
 * Created by wangjianqiang on 2017/2/16.
 */
public class BatteryViewWhite extends FrameLayout {
    private BatteryWhite battery_img;
    private ImageView lightning_img;
    private TextView battery_txt;

    private boolean charging = false;
    private boolean full = false;
    private int percent = 0;

    public BatteryViewWhite(Context context) {
        super(context);
        init(context);
    }

    public BatteryViewWhite(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public BatteryViewWhite(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.battery_white_view, this);
        battery_img = (BatteryWhite) findViewById(R.id.battery_img);
        lightning_img = (ImageView) findViewById(R.id.lightning_img);
        battery_txt = (TextView) findViewById(R.id.battery_txt);
    }

    public void setBatteryPercent(int percent) {
        this.percent = percent;
        battery_txt.setText(percent + "%");
        battery_img.setBatteryPercent(percent);
        if (battery_img.getBatteryPercent() <= 20) {
            if (battery_img.getColor() != Color.GREEN)
                battery_img.setColor(Color.RED);
        }
    }

    public void setBatteryFullState(boolean full) {
        this.full = full;
        if (full) battery_img.setColor(Color.WHITE);
        lightning_img.setVisibility(View.GONE);
    }

    public void setBatteryChargingState(boolean charging) {
        this.charging = charging;
        if (charging) {
            battery_img.setColor(Color.GREEN);
            lightning_img.setVisibility(View.VISIBLE);
        } else {
            if (battery_img.getBatteryPercent() > 20)
                battery_img.setColor(Color.WHITE);
            else
                battery_img.setColor(Color.RED);

            lightning_img.setVisibility(View.GONE);
        }
    }
}
